const Mock = require('mockjs');
const moment=require("moment")

  const randomDate = (startDate, endDate) => {
    let date = new Date(+startDate + Math.random() * (endDate - startDate));
    let hour = (0 + Math.random() * (23 - 0)) | 0;
    let minute = (0 + Math.random() * (59 - 0)) | 0;
    let second = (0 + Math.random() * (59 - 0)) | 0;
    date.setHours(hour);
    date.setMinutes(minute);
    date.setSeconds(second);
    return date;
  };
    // 生产当月的开始日期
  const startDate = new Date("2023-06-20 00:00:00");
    // 截止日期
  const endDate = new Date("2023-06-27 17:00:00"); 
const chatList = Mock.mock({
  'chatList|50': [
    {
      'id|+1': 1,
      'avatar': "@image('100x100', '#894FC4', '#FFF', 'png', 'mock')",
      'name': '@cname',
      'msg': '@ctitle(16)',
      
      'date|1':'YYYY-MM-DD HH:mm:ss',
      'isRead': '@boolean',
    }
  ]
});
const likeList=Mock.mock({
  'likeList|6':[
    {
      'id|+1':1,
      'avatar':"@image('200x200', '#8fcfff', '#FFF', 'png', '>.<')",
      'name':'@cname',
      'time':'@datetime("MM-dd HH:mm")',
      'img':"@image('200x200', '#894FC4', '#FFF', 'png', 'o.O')",
      'content':'@cparagraph(2)',
      'msg': '请问你那场几点结束呢？',

    }
  ]
})
const systemList=Mock.mock({
  'systemList|8':[
    {
      'id|+1':1,
      'date|1':'@date("yyyy-MM-dd")',
      'tit|0-3':1,
      'content':'@cparagraph(2)',
    }
  ]
})

for(var i=0;i<50;i++){
  chatList.chatList[i].date = moment(randomDate(startDate, endDate)).format(
    "YYYY-MM-DD HH:mm:ss"
  );
}
for(var i=0;i<8;i++){
  systemList.systemList[i].date = moment(randomDate(startDate, endDate)).format(
    "YYYY-MM-DD"
  );
}
module.exports = app => {  
 
  const getChatList = (req) => {
    // console.log(req)
    if(req.query){
      const {page,pageSize} = req.query
      const sortedList = chatList.chatList.slice().sort((a, b) => new Date(b.date) - new Date(a.date));
      return sortedList.slice((page-1)*pageSize,page*pageSize) 
    }

  }
  const getLikeList=(req)=>{
    return likeList.likeList
  }
  const getSystemList=(req)=>{
    const List = systemList.systemList.slice().sort((a, b) => new Date(b.date) - new Date(a.date));
    return List
  }
  app.get('/news/message/list', (req, res) => {
    res.send({
      code: 0,
      msg: 'ok',
      data: {
        
        data:getSystemList(req)
      }
  })
  })

  app.get('/news/chat/list', (req, res) => {
    res.send({
      code: 0,
      msg: 'ok',
      data: {
        total:chatList.chatList.length,
        data:getChatList(req)
      }
  })
  })
  app.get('/new/like/list', (req, res) => {
    res.send({
      code: 0,
      msg: 'ok',
      data: {
        data:getLikeList(req)
      }
    })
  })
  
}